package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TGeofence;
import com.ruoyi.system.service.ITGeofenceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地理围栏Controller
 * 
 * @author ruoyi
 * @date 2025-03-09
 */
@RestController
@Api("地理围栏管理")
@RequestMapping("/system/geofence")
public class TGeofenceController extends BaseController
{
    @Autowired
    private ITGeofenceService tGeofenceService;

    /**
     * 查询地理围栏列表
     */
    //@PreAuthorize("@ss.hasPermi('system:geofence:list')")
    @GetMapping("/list")
    @ApiOperation(value = "地理围栏列表")
    public TableDataInfo list(TGeofence tGeofence)
    {
        startPage();
        List<TGeofence> list = tGeofenceService.selectTGeofenceList(tGeofence);
        return getDataTable(list);
    }

    /**
     * 导出地理围栏列表
     */
    //@PreAuthorize("@ss.hasPermi('system:geofence:export')")
    @Log(title = "地理围栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TGeofence tGeofence)
    {
        List<TGeofence> list = tGeofenceService.selectTGeofenceList(tGeofence);
        ExcelUtil<TGeofence> util = new ExcelUtil<TGeofence>(TGeofence.class);
        util.exportExcel(response, list, "地理围栏数据");
    }

    /**
     * 获取地理围栏详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:geofence:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "地理围栏详情")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tGeofenceService.selectTGeofenceById(id));
    }

    /**
     * 新增地理围栏
     */
    //@PreAuthorize("@ss.hasPermi('system:geofence:add')")
    @Log(title = "地理围栏", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "地理围栏新增")
    public AjaxResult add(@RequestBody TGeofence tGeofence)
    {
        return toAjax(tGeofenceService.insertTGeofence(tGeofence));
    }

    /**
     * 修改地理围栏
     */
    //@PreAuthorize("@ss.hasPermi('system:geofence:edit')")
    @Log(title = "地理围栏", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "地理围栏编辑")
    public AjaxResult edit(@RequestBody TGeofence tGeofence)
    {
        return toAjax(tGeofenceService.updateTGeofence(tGeofence));
    }

    /**
     * 删除地理围栏
     */
    //@PreAuthorize("@ss.hasPermi('system:geofence:remove')")
    @Log(title = "地理围栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value = "删除地理围栏")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tGeofenceService.deleteTGeofenceByIds(ids));
    }
}
